package com.osce.web.controller.system;

import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.entity.entity.SysUserInfo;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.system.ISysUserInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户信息扩展表Controller
 *
 * @author zzx
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/system/user_info")
public class SysUserInfoController extends BaseController {

    @Resource
    private ISysUserInfoService sysUserInfoService;

    /**
     * 查询用户信息扩展表列表
     */
    @PreAuthorize("@ss.hasPermi('system:user_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserInfo sysUserInfo) {
        startPage();
        List<SysUserInfo> list = sysUserInfoService.selectSysUserInfoList(sysUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出用户信息扩展表列表
     */
    @PreAuthorize("@ss.hasPermi('system:user_info:export')")
    @Log(title = "用户信息扩展表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserInfo sysUserInfo) {
        List<SysUserInfo> list = sysUserInfoService.selectSysUserInfoList(sysUserInfo);
        ExcelUtil<SysUserInfo> util = new ExcelUtil<SysUserInfo>(SysUserInfo.class);
        util.exportExcel(response, list, "用户信息扩展表数据");
    }

    /**
     * 获取用户信息扩展表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user_info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysUserInfoService.selectSysUserInfoById(id));
    }

    /**
     * 新增用户信息扩展表
     */
    @PreAuthorize("@ss.hasPermi('system:user_info:add')")
    @Log(title = "用户信息扩展表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserInfo sysUserInfo) {
        return toAjax(sysUserInfoService.insertSysUserInfo(sysUserInfo));
    }

    /**
     * 修改用户信息扩展表
     */
    @PreAuthorize("@ss.hasPermi('system:user_info:edit')")
    @Log(title = "用户信息扩展表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserInfo sysUserInfo) {
        return toAjax(sysUserInfoService.updateSysUserInfo(sysUserInfo));
    }

    /**
     * 删除用户信息扩展表
     */
    @PreAuthorize("@ss.hasPermi('system:user_info:remove')")
    @Log(title = "用户信息扩展表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysUserInfoService.deleteSysUserInfoByIds(ids));
    }
}
